package BookManagement.dao;

import BookManagement.domain.Book;
import BookManagement.domain.Stock;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

@Repository
public interface StockDao {

    @Select("<script>"+"select * from stock "+
            "<where>"+"<if test='bookISBN!=null'>"+"bookISBN=#{bookISBN}"+"</if>"+"</where>"+
            "<if test='start!=null and size!=null'>"+"limit #{start},#{size}"+"</if>"
            +"</script>"
    )
    public List<Stock> findStocks(HashMap<String,Object> map);

    @Select("<script>"+"select count(*) from stock "+
            "<where>"+"<if test='bookISBN!=null'>"+"bookISBN=#{bookISBN}"+"</if>"+"</where>"
            +"</script>"
    )
    public int getTotalStocks(HashMap<String,Object> map);

    @Insert("insert into stock values(#{bookISBN},#{bookName},#{counts},#{address},#{time})")
    public int addStocking(Stock stock);
}
